export function parseQueryString(query) {
  const hash = query.split('?')[1]
  if (!hash) return {}
  
  return hash.split('&').reduce((params, param) => {
    const [key, value] = param.split('=')
    params[key] = decodeURIComponent(value || '')
    return params
  }, {})
}

function padZero(num) {
  return num < 10 ? `0${num}` : num
}

export function formatTime(timestamp) {
  const date = new Date(timestamp)
  return `${date.getFullYear()}-${padZero(date.getMonth() + 1)}-${padZero(date.getDate())} ${padZero(date.getHours())}:${padZero(date.getMinutes())}:${padZero(date.getSeconds())}`
}

// uuid生成
export function generateUUID() {
  return 'xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random() * 16 | 0,
        v = c === 'x' ? r : (r & 0x3 | 0x8)
    return v.toString(16)
  })
}